<?php

namespace Admin\Model;

use Think\Model;

/**
* 订单模型
*/
class OrderModel extends Model
{
	/**
	 * [订单列表]
	 * @return [array]   数据    [description]
	 */
	public function showlist($range,$mobile){
		switch ($range) {
			case '1':
				$where['order'] = array('gt',strtotime(date('Y-m-d',time())));
				break;
			case '2':
				$where['order'] = array('gt',strtotime(date('Y-m',time())));
				break;
		}
		if (!empty($mobile)) {
			$where['u.mobile'] = array('like',"%$mobile%");
		}
		//分页
		$count = $this -> where($where) -> count();
		$page = new \Think\Page($count, 10);
		$page -> setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
		$pages = $page -> show();

		$list = $this -> alias('o') -> field('o.*,u.mobile') -> join('tutor_user_member as u on o.uid=u.id') -> order('o.id desc') -> where($where) -> limit($page->firstRow, $page->listRows) -> select();
		return array($list,$pages);
	}
	/**
	 * 获取要退订的学生
	 */
	public function getAll(){
		$map['m.cancel_time'] = array('lt',time());
		$map['m.cancel'] = 2;
		$data = $this
		     ->alias('o')
		     ->join('tutor_user_member as u on o.uid = u.id')
		     ->join('tutor_mycourse as m on o.order = m.order')
		     ->join('tutor_course as c on c.id = o.cid')
		     ->field('o.order,u.nickname,u.age,u.mobile,c.title,m.cancel_time')
		     ->where($map)
		     ->select();
		     return $data;
	}
	/**
	 * 不同意退订
	 */
	public function notCancel($order){
		$data['cancel_time'] = "";
		$data['cancel']      = 0;
		return D('Home/Mycourse') -> where(array('order' =>$order)) ->save($data);
	}
}